package com.caozhi.mspeoject.nb_insurance.controller;

import com.caozhi.mspeoject.nb_insurance.bean.Insurance;
import com.caozhi.mspeoject.nb_insurance.service.InsuranceService;
import com.woniuxy.boot.common.pojo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("insurance")
public class InsuranceController {
    @Autowired
    private InsuranceService insuranceService;
    @GetMapping("getall")
    public ResponseResult<List<Insurance>> getAllInsurance(){
        return new ResponseResult<>(insuranceService.getInsurance());
    }
    @PostMapping("add")
    public ResponseResult<Void> addInsurance(@RequestBody Insurance insurance){
        try{insuranceService.addInsurance(insurance);
            return ResponseResult.SUCCESS;
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResponseResult.FAIL;
    }
    @GetMapping("getPrice")
    public BigDecimal getPrice(@RequestParam("id") Long id){
       return insuranceService.getInsurancePrice(id);
    }
    @GetMapping("getById")
    public Insurance getById(@RequestParam("id") Long id){
        return insuranceService.getInsuranceById(id);
    }

}
